#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
const int maxn = 1e5+10;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
int d[4][2]={1,0,0,1,-1,0,0,-1};
ll tree[maxn<<1],ans[maxn];
ll n,m,l,r;
int lowbit(int x)
{
    return x&(-x);
}
void add(int pos,int x)
{
    while(pos<=n)
    {
        tree[pos]+=x;
        pos+=lowbit(pos);
    }
}
int query(int pos)
{
    int res=0;
    while(pos>0)
    {
        res+=tree[pos];
        pos-=lowbit(pos);
    }
    return res;
 } 
int main() {
    ios::sync_with_stdio(0);
    #ifdef Uncle_drew
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #else
    #endif
    cin>>n>>m;
    while(m--){
        cin>>l>>r;
        add(l,1);
        add(r+1,-1);
    }
    ll minn=0x3f3f3f3f3f3f3f3f;
    for(int i=1;i<=n;i++){
        ans[i]=query(i);
        minn=min(minn,ans[i]);
    }
    for(int i=1;i<=n;i++)   ans[i]-=minn;
    sort(ans+1,ans+1+n);
    ll answer=minn*(1+n)*n/2;
    for(int i=n;i>=1;i--){
        answer+=ans[i]*i;
    }
    cout<<answer<<endl;
    return 0;
}